package cn.antia.cep.common;

import cn.antia.cep.busi.BusiException;
import cn.antia.cep.busi.DbHibernateService;
import cn.antia.cep.db.hibernate.bean.SysException;

import java.util.Date;

/**
 * User: xiao
 * Date: 2007-8-6
 * Time: 10:10:07
 */
public class SysExceptionTool {
    private static DbHibernateService service;
    
    /**
     * add exception to db
     * @param e
     */
    public static void addExceptionInfo(AntiaException e){
        if(service == null) {
            service = (DbHibernateService) ContextBean.getBean("dbHibernateService");
        }
        SysException exception = new SysException();
        exception.setCode(e.getCode());
        exception.setMsg(e.getDefineMsg());
        exception.setInfo(e.getErrorMsg());
        exception.setEtype(e.getEtype());
        exception.setOccurTime(new Date());
        try{
            service.create(exception);
        }catch(BusiException be){
            AntiaLog.error("Add exception info to db occur error!Maybe is db connection exception or the server ERROR!");
            AntiaLog.error(e.getStackTrace().toString());
        }
    }
}
